<template>
  <el-dialog
    v-if="load"
    title="历史采购订单价格"
    v-model="visible"
    align-center
    width="1100px"
    @close="handleClose"
    draggable
    :z-index="2000"
  >
    <div class="my-2">
      <span class="text-gray-400">sku:</span> {{ form.sku }}
      <span class="text-gray-400 ml-5">产品名称:</span> {{ form.sku_name }}
    </div>
    <vxe-table ref="table" :data="form.list">
      <vxe-column title="采购单号" field="purchase_no"></vxe-column>
      <vxe-column title="供应商" field="supplier_name">
        <template #default="{ row }">
          <dataAuthority
            auth="supplier_name"
            :value="row.supplier_name"
            :default_value="row.supplier_code"
          ></dataAuthority>
        </template>
      </vxe-column>
      <vxe-column title="下单价" field="total_price" width="70"></vxe-column>
      <vxe-column title="下单数量" field="purchase_num" width="80"></vxe-column>
      <vxe-column title="开票税点" field="tax_rate" width="80"></vxe-column>
      <vxe-column title="含税价" field="unit_price_tax" width="70"></vxe-column>
      <vxe-column title="单个运费" field="unit_tracking_price" width="80"></vxe-column>
      <vxe-column title="单个采购成本" width="70">
        <template #default="{ row }">
          {{
            row.is_drawback === 2 ? row.unit_purchase_price_tax : row.unit_purchase_price
          }}
        </template>
      </vxe-column>
      <vxe-column field="aaa">
        <template #header> 下单人员<br />采购时间 </template>
        <template #default="{ row }">
          {{ row.create_user }}<br />{{ row.create_time }}
        </template>
      </vxe-column>
      <vxe-column title="采购耗时" field="purchase_date"></vxe-column>
    </vxe-table>
    <template #footer>
      <el-button @click="close">关 闭</el-button>
    </template>
  </el-dialog>
</template>

<script setup>
// import api from './VHistory/api'
import { getPurchaseProcessHistory } from "@/api/index.js";
const emit = defineEmits(["close", "success"]);

const load = ref(false);
const visible = ref(false);
let loadings = reactive({});

const form = ref({});

// 打开弹窗
const open = async (sku) => {
  if (!load.value) {
    load.value = true;
    await 1;
  }
  form.value = {
    list: [],
    sku: "",
    sku_name: "",
  };
  getPurchaseProcessHistory({ sku }).then((res) => {
    form.value = res.data;
  });
  loadings = reactive({});
  visible.value = true;
};
// 关闭弹窗
const close = () => {
  visible.value = false;
};

const handleClose = () => {
  emit("close");
};

defineExpose({ open });
</script>
